﻿package net.steam.easyjoboa.biz.impl;

import java.util.ArrayList;
import java.util.List;

import net.steam.easyjoboa.biz.RolesBiz;
import net.steam.easyjoboa.dao.EmployeeDao;
import net.steam.easyjoboa.dao.RolesDao;
import net.steam.easyjoboa.entity.Employee;
import net.steam.easyjoboa.entity.Roles;

public class RolesBizImpl implements RolesBiz {

	/**
	 * 添加角色
	 */
	private RolesDao rolesDao;
	private EmployeeDao employeeDao;
	public int addRoles(Roles roles) {
		int key=0;
		try {
			key=rolesDao.addEntity(roles);
		} catch (Exception e) {
			e.printStackTrace();
			return key;
		}
		return key;
	}
	/**
	 * 查找所有的角色
	 */
	public List<Roles> findAllRoles() {
		String hql="from Roles";
		List<Roles> roles=rolesDao.find(hql);
		if(roles.size()!=0){
			return roles;
		}else{
		return null;
		}
	}
	
	/**
	 * 根据ID查找角色，ID可以是多个
	 * 返回一个角色的集合
	 */
	public List<Roles> findById(int[] key) {
		
		String hql="from Roles r where r.roleId in (";
		for(int i=0;i<key.length;i++){
			if(i!=key.length-1){
				hql+=key[i]+",";
			}else{
				hql+=key[i];
			}
		}
		hql+=")";
		List<Roles> list=rolesDao.find(hql);
		return list;
	}
	//赋予基本权限
	public void updateE(Employee employee) {
		try{
			List<Roles> roleses=new ArrayList<Roles>();
			Roles r=rolesDao.findById(4);
			roleses.add(r);
			employee.setRoleses(roleses);
			employeeDao.updateEntity(employee);
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	
	public void setRolesDao(RolesDao rolesDao) {
		this.rolesDao = rolesDao;
	}
	public void setEmployeeDao(EmployeeDao employeeDao) {
		this.employeeDao = employeeDao;
	}

	

}
